package com.coolw.log4j2.mask.log;

import java.util.HashMap;
import java.util.Map;

/**
 * 日志脱敏规则
 *
 * @author coolw
 * @date 2024/4/19 17:03
 */
public class Log4j2MaskRule {

    public static Map<String, String> regularMap = new HashMap<>();

    /**
     * 脱敏关键字
     */
    public static final String NAME_KEY = "name,userName,custName";
    public static final String IDCARD_KEY = "idCard,idCardNo";
    public static final String MOBILE_KEY = "mobile,mobileNo,phone,phoneNo";

    /**
     * 脱敏正则匹配
     */
    private static final String NAME_REGEXP = "[\\u4e00-\\u9fa5]{2,4}";
    private static final String IDCARD_REGEXP = "(\\d{17}[0-9Xx]|\\d{14}[0-9Xx])";
    private static final String MOBILE_REGEXP = "(?<!\\d)(?:(?:1[3456789]\\d{9})|(?:861[356789]\\d{9}))(?!\\d)";

    static {
        regularMap.put(NAME_KEY, NAME_REGEXP);
        regularMap.put(IDCARD_KEY, IDCARD_REGEXP);
        regularMap.put(MOBILE_KEY, MOBILE_REGEXP);
    }
}
